local CommonOHOH = _G.CommonOHOH;
local M = CommonOHOH.class.new(script, CommonOHOH.files.BaseComponent(),script.Parent.Name.."_base");
local gRollCd = CommonOHOH.config.Game.RollCd

--数据层接口
function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);
    self.player=self.parent
    self.UpdateEvent=self.player.RngDataLayerUpdateEvent
    self.UpdateEvent:Connect(function(isSave)
            if isSave then
                self:Save()
            end
    end)
end;


function M.dtor(self)
	M.super.dtor(self);
end;

--存档
function M.Save(self)

end

function M.InitData(self)
    self:UpdateBase()
    self.RollSpeedAdder=0
    self.LuckyAdder=0
    self.ShinyLuckyAdder=0
    self.RainbowLuckyAdder=0
    self.VoidLuckyAdder=0
end

function M.UpdateBase(self)


    self.BaseRollSpeed=self.DataBase:GetData("base").RollSpeed
    self.BaseLucky=self.DataBase:GetData("base").Lucky
    self.BaseShinyLucky=self.DataBase:GetData("base").ShinyLuck
    self.BaseRainbowLucky=self.DataBase:GetData("base").RainbowLuck
    self.BaseVoidLucky=self.DataBase:GetData("base").VoidLuck


end


----------------------------------对外接口-------------------------------------------------
------------------写----------------------
-- 永久增加roll速度, 参数：比列数 (如增加10%,则传入0.001)
function M.AddRollSpeed(self,add,isSave)
    if isSave then
        self.BaseRollSpeed=self.BaseRollSpeed+add
    else
        self.RollSpeedAdder=self.RollSpeedAdder+add
    end
    self.UpdateEvent:Action(isSave)
end

--永久增加基础luck值，参数：自然数 
function M.AddLucky(self,add,isSave)
    if isSave then
        self.BaseLucky=self.BaseLucky+add
    else
        self.LuckyAdder=self.LuckyAdder+add
    end
    self.UpdateEvent:Action(isSave)
end

--永久增加ShinyLucky值， 参数：比列数 (如增加10%,则传入0.001)
function M.AddShinyLucky(self,add,isSave)
    if isSave then
        self.BaseShinyLucky=self.BaseShinyLucky+add
    else
        self.ShinyLuckyAdder=self.ShinyLuckyAdder+add
    end
    self.UpdateEvent:Action(isSave)
end


--永久增加RainbowLucky值， 参数：比列数 (如增加10%,则传入0.001)
function M.AddRainbowLucky(self,add,isSave)
    if isSave then
        self.BaseRainbowLucky=self.BaseRainbowLucky+add
    else
        self.RainbowLuckyAdder=self.RainbowLuckyAdder+add
    end
    self.UpdateEvent:Action(isSave)
end

--永久增加AddVoidLucky值， 参数：比列数 (如增加10%,则传入0.001)
function M.AddVoidLucky(self,add,isSave)
    if isSave then
        self.BaseVoidLucky=self.BaseVoidLucky+add
    else
        self.VoidLuckyAdder=self.VoidLuckyAdder+add
    end
    self.UpdateEvent:Action(isSave)
end

------------------读----------------------
-- 获取Roll速度
function M.GetRollSpeed(self)
    return  self.BaseRollSpeed+self.RollSpeedAdder
end

-- 获取基础Lucky
function M.GetLucky(self)
    return self.BaseLucky+ self.LuckyAdder
end

-- 获取ShinyLucky
function M.GetShinyLucky(self)
     return self.BaseShinyLucky+ self.ShinyLuckyAdder
end

-- 获取RainbowLucky
function M.GetRainbowLucky(self)
    return self.BaseRainbowLucky+ self.RainbowLuckyAdder
end
-- 获取VoidLucky
function M.GetVoidLucky(self)
    return self.BaseVoidLucky+ self.VoidLuckyAdder
end

--获取品阶Luck值数组
function M.GetGradeLuckyList(self)
    return {
        [1]=0,
        [2]=self:GetShinyLucky(),
        [3]=self:GetRainbowLucky(),
        [4]=self:GetVoidLucky()
    }
end

--获取品阶预定结果
function M.GetPredeterminedGrade(self)
   local list=  self.player.PredeterminedGradeEvent:Action()
   for _,v in pairs(list) do
        return v
   end
end

--获取随机次数
function M.GetRollCount(self)
    local list= self.player.RollDropMulEvent:Action()
    local sum=1
    for _,v in pairs(list) do
        sum=sum+v
    end
    return sum
end


-- 获取RollCd
function M.GetRollCd(self)
    local speed=self:GetRollSpeed()
    return gRollCd/(1+speed)
end



return M